#coding=utf-8
#!/usr/bin/env python3

"""生成字段属性文件(field-attributes.adoc)"""

import csv
import time
import sys

def main():
    """生成字段属性文件"""

    csv_name = "./field-dictionary.csv"
    adoc_name = "./field-dictionary.adoc"

    with open(adoc_name, "w", encoding='UTF-8') as adoc_file:

        __write_comment(adoc_file)

        with open(csv_name, "r", encoding='UTF-8') as csv_file:
            reader = csv.reader(csv_file)
            for row in reader:
                field_name = row[0]

                adoc_file.writelines([
                    f"\n",
                    f":{field_name}_t: {row[1]}\n",
                    f":{field_name}_f: {row[2]}\n",
                    f":{field_name}_d: {row[3]}\n",
                   # f":{field_name}_e: {row[4]}\n",
                ])

def __write_comment(to_file):
    now = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
    to_file.writelines([
        f"// 自动生成时间：{now}\n",
        f"// ************************\n",
        f"// 不要手动修改此文件!\n",
        f"// 不要手动修改此文件!!\n",
        f"// 不要手动修改此文件!!!\n",
        f"// ************************\n\n",
        f"// 定义说明：\n",
        f"// xxx_t: API时数据类型\n",
        f"// xxx_f: 文件时数据类型\n",
        f"// xxx_d: 描述\n",
        f"// xxx_e: 示例\n",
    ])

if __name__ == '__main__':
    main()
